package tools

import org.apache.spark.{SparkConf, SparkContext}
import utils.JedisPools

/**
  * 建立我们的省份编码匹配库
  */
object ProvinceMapping {
  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf()
    sparkConf.setAppName(s"${this.getClass.getSimpleName}")
    sparkConf.setMaster("local[*]")
    // RDD 序列化到磁盘 worker与worker之间的数据传输
    sparkConf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")

    val sc = new SparkContext(sparkConf)


    sc.textFile("F:\\mrdata\\mobileAnaluzing\\provinceMapping").map(line => {
      val fields = line.split(",", -1)
      (fields(0), fields(1))
    }).foreachPartition(itr=>{
      val jedis = JedisPools.getJedis()

      itr.foreach(f = t => {
        val key = "CnMobileProvinceMapping"
       jedis.hset(key,t._1,t._2)

      })

      jedis.close()

    })

  }
}
